package com.itheima.tliasmanagent.controller;

import com.itheima.tliasmanagent.anno.Log;
import com.itheima.tliasmanagent.pojo.Dept;
import com.itheima.tliasmanagent.pojo.Result;
import com.itheima.tliasmanagent.service.DeptService;
import com.itheima.tliasmanagent.service.impl.DeptServiceImpl;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    // 体现多态


    @Autowired
    private DeptService deptService ;

//    @RequestMapping(value = "/depts",method = RequestMethod.GET)
    @GetMapping
    public Result list() throws IOException {
        log.debug("我是debug........");
        log.info("我是debug........");
        List<Dept> deptList = deptService.getDeptList();
        //3. 响应数据
        return Result.success(deptList);
        //return collect;
    }


 /*   @DeleteMapping("/depts")
    public Result delete(HttpServletRequest request){
        String idStr = request.getParameter("id");
        int id = Integer.parseInt(idStr);


        return Result.success();
    }*/


 /*   @DeleteMapping("/depts")
    public Result delete2(@RequestParam("id") Integer deptId){

        System.out.println(deptId);
        return Result.success();

    }*/

    @DeleteMapping
    @Log
    public Result delete2(Integer id){
        System.out.println(id);
        deptService.delete(id); // 完成数据删除的功能
        return Result.success();

    }


    @PostMapping
    @Log
    public Result add(@RequestBody Dept dept){

        deptService.add(dept);// 部门新增操作

        return Result.success();
    }


    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        System.out.println(id);

       Dept dept= deptService.getInfo(id);// 部门信息的查询
        return Result.success(dept);
    }


    @PutMapping
    @Log
    public Result update(@RequestBody Dept dept){
        deptService.update(dept);// 实现数据更新
        return Result.success();
    }


}
